package com.hb.common.controller;

import com.hb.common.dto.RestoreDto;
import com.hb.common.exception.DbBackupException;
import com.hb.common.service.DbBackupService;
import com.hb.common.util.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
public class DbBackupController {

    @Resource
    private DbBackupService dbBackupService;

    /**
     * 数据库备份
     */
    @PostMapping("/db-backup/backup/{id}")
    public Result<Boolean> backup(@PathVariable Integer id) throws DbBackupException {
        boolean backup = dbBackupService.backup(id);
        return Result.success(backup);
    }

    /**
     * 数据库还原
     */
    @PostMapping("/db-backup/restore")
    public Result<Boolean> restore(@RequestBody RestoreDto restoreDto) throws DbBackupException {
        boolean restore = dbBackupService.restore(restoreDto);
        return Result.success(restore);
    }
}
